package com.travel.server.manager.impl.command.data;

import com.travel.common.util.CommonUtil;
import com.travel.server.manager.dto.request.data.QueryPageDataRequest;
import com.travel.server.manager.dto.response.data.QueryPageDataResponse;
import com.travel.server.manager.dto.response.data.QueryPageDataResponse.PageItem;
import com.travel.server.manager.dto.response.data.QueryPageDataResponse.VisitAreaItem;
import com.travel.server.manager.impl.command.AbstractCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: LiZhenhui
 * @Date: 2018/12/14 19:11
 * @Desc:
 */
@Component
@Slf4j
public class QueryPageDataCommand extends AbstractCommand<QueryPageDataRequest, QueryPageDataResponse> {
    @Override
    protected void checkInput(QueryPageDataRequest request) {
        checkTimeInput(request);
        checkPageInput(request);
    }

    @Override
    public QueryPageDataResponse handle(QueryPageDataRequest request) {
        checkInput(request);
        QueryPageDataResponse response = new QueryPageDataResponse();
        response.setVisit("0");
        response.setBrowser("0");
        response.setCommodityBrowser("0");
        response.setCommodityExpose("0");
        response.setCommodityVisit("0");
        List<PageItem> pageList = new ArrayList<>();
        response.setPageList(pageList);

        response.setVisitAreaList(makeAreaList());
        return response;
    }

    public List<VisitAreaItem> makeAreaList(){
        List<VisitAreaItem> areaList = new ArrayList<>();
        int i = 1;
        for(String area :  CommonUtil.AREA_LIST){
            VisitAreaItem item = new VisitAreaItem();
            item.setArea(area);
            item.setBrowser("0");
            item.setCommodityBrowser("0");
            item.setCommodityVisit("0");
            item.setVisit("0");
            item.setNum((i++) + "");
            areaList.add(item);
        }
        return areaList;
    }
}
